package gwtool.container;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;

public class InlinePruefung implements Cloneable {

	private String identifier = "";

	private String name = "";

	private int intervall = 0;

	private String kommentar = "";

	public InlinePruefung() {

	}

	public InlinePruefung(String name, int interval, String kommentar) {

		this.name = name;
		this.intervall = interval;
		this.kommentar = kommentar;
		identifier = createNewIdentifer();
	}

	public long getTageBisLong(Date date) {

		GregorianCalendar today = new GregorianCalendar();
		GregorianCalendar geprueftAm = new GregorianCalendar();
		geprueftAm.setTime(date);
		geprueftAm.add(Calendar.MONTH, intervall);
		return (geprueftAm.getTimeInMillis() - today.getTimeInMillis()) / (24 * 60 * 60 * 1000);
	}

	public Date getDateumNaechstePruefung(Date date) {

		GregorianCalendar geprueftAm = new GregorianCalendar();
		geprueftAm.setTime(date);
		geprueftAm.add(Calendar.MONTH, intervall);
		Date newDate = geprueftAm.getTime();
		return newDate;
	}

	public String createNewIdentifer() {

		return name + intervall + new Random().nextLong();
	}

	@Override
	public String toString() {

		return name + "   " + kommentar;
	}

	public String getName() {

		return name;
	}

	public void setName(String name) {

		this.name = name;
	}

	public int getIntervall() {

		return intervall;
	}

	public void setIntervall(int intervall) {

		this.intervall = intervall;
	}

	public String getKommentar() {

		return kommentar;
	}

	public void setKommentar(String kommentar) {

		this.kommentar = kommentar;
	}

	public String getIdentifier() {

		return identifier;
	}

	public void setIdentifier(String identifier) {

		this.identifier = identifier;
	}

	@Override
	public InlinePruefung clone() {
		InlinePruefung p = new InlinePruefung(name, intervall, kommentar);
		p.setIdentifier(identifier);
		return p;
	}
}
